unit uFileConfigDataBase;

interface

uses
  Classes, Inifiles, SysUtils;

type
  TFileConfigDataBase = class(TComponent)
  private
    FFileName: string;
    FIniFile: TIniFile;
    FServerName: string;
    FDatabase: string;
    FUserName: string;
    FPassword: string;
  public
    constructor Create(AOwner: TComponent; IniFileName: string); reintroduce;
    procedure LoadFromFile;
    procedure SaveToFile;
    property FileName: string read FFileName;
    property ServerName: string read FServerName write FServerName;
    property Database: string read FDatabase write FDatabase;
    property UserName: string read FUserName write FUserName;
    property Password: string read FPassword write FPassword;
  end;

implementation

uses uFunction;

{ TFileConfigDataBase }

constructor TFileConfigDataBase.Create(AOwner: TComponent; IniFileName: string);
begin
  FFileName := IniFileName;
  LoadFromFile;
end;

procedure TFileConfigDataBase.LoadFromFile;
begin
  FIniFile := TIniFile.Create(FFileName);

  FServerName:= FIniFile.ReadString('Database', 'ServerName', '127.0.0.1');
  FDatabase  := FIniFile.ReadString('Database', 'DataBase', '');
  FUserName  := FIniFile.ReadString('Database', 'UserName', 'SYSDBA');
  FPassword  := FIniFile.ReadString('Database', 'Password', 'masterkey');

  FIniFile.Free;
end;

procedure TFileConfigDataBase.SaveToFile;
begin
  FIniFile := TIniFile.Create(FFileName);

  FIniFile.WriteString('Database', 'ServerName', FServerName);
  FIniFile.WriteString('Database', 'DataBase'  , FDatabase  );
  FIniFile.WriteString('Database', 'UserName'  , FUserName  );
  FIniFile.WriteString('Database', 'Password'  , FPassword  );

  FIniFile.Free;
end;

end.
